package com.mydesignpattern.beijing.composite.folder;

import com.mydesignpattern.beijing.composite.MyFile;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件夹类
 */
public class MyFolder extends MyFile {

    private List<MyFile> fileList = new ArrayList<MyFile>();

    public MyFolder(){}

    public MyFolder(String name){
        this.name = name;
    }

    //打印名字
    public void printFiles(){
        System.out.println("文件夹："+this.getName());
        for(MyFile file:fileList){
            file.printFiles();
        }
    }

    //添加文件
    public void addFile(MyFile file){
        this.fileList.add(file);
    }

    //删除文件
    public void removeFile(String name){
        for(MyFile file:fileList){
            if(name.equals(file.getName())){//
                fileList.remove(file);
            }
        }

    }


}
